<template>
  <div>
    <n-drawer v-model:show="showModal" :width="dialogWidth">
      <n-drawer-content title="店铺管理详情" closable>
        <n-spin :show="loading" description="请稍候...">
          <n-descriptions label-placement="left" class="py-2" :column="1">
            <n-descriptions-item>
              <template #label>
                店铺名称
              </template>
              {{ formValue.name }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                LOGO
              </template>
              <span v-html="formValue.logo"></span>
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                评分
              </template>
              {{ formValue.rating }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                评论数
              </template>
              {{ formValue.reviews }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                行业分类
              </template>
              {{ formValue.category }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                标签
              </template>
              {{ formValue.tags }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                是否推荐
              </template>
              {{ formValue.isCollected }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                经度
              </template>
              {{ formValue.latitude }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                纬度
              </template>
              {{ formValue.longitude }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                地址
              </template>
              {{ formValue.address }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                联系电话
              </template>
              {{ formValue.contactPhone }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                简介
              </template>
              <span v-html="formValue.intro"></span>
            </n-descriptions-item>
          </n-descriptions>
        </n-spin>
      </n-drawer-content>
    </n-drawer>
  </div>
</template>

<script lang="ts" setup>
  import { computed, ref } from 'vue';
  import { useMessage } from 'naive-ui';
  import { View } from '@/api/cardShop';
  import { State, newState } from './model';
  import { adaModalWidth } from '@/utils/hotgo';
  import { getFileExt } from '@/utils/urlUtils';

  const message = useMessage();

  const loading = ref(false);
  const showModal = ref(false);
  const formValue = ref(newState(null));
  const dialogWidth = computed(() => {
    return adaModalWidth(580);
  });
  const fileAvatarCSS = computed(() => {
    return {
      '--n-merged-size': `var(--n-avatar-size-override, 80px)`,
      '--n-font-size': `18px`,
    };
  });

  // 下载
  function download(url: string) {
    window.open(url);
  }

  // 打开模态框
  function openModal(state: State) {
    showModal.value = true;
    loading.value = true;
    View({ id: state.id })
      .then((res) => {
        formValue.value = res;
      })
      .finally(() => {
        loading.value = false;
      });
  }

  defineExpose({
    openModal,
  });
</script>

<style lang="less" scoped></style>